﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class youhui : Form
    {
        public youhui()
        {
            InitializeComponent();
        }
        string conStr = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        DataSet ds = new DataSet();
        public string jine;
        public string shuoming;
        private void youhui_Load(object sender, EventArgs e)
        {
            string sql = @"SELECT  UserTpye.userName, [User].id
FROM      [User] INNER JOIN
                   UserTpye ON [User].userID = UserTpye.userID";
            SqlConnection sqlcon = new SqlConnection(conStr);
            SqlDataAdapter adapter = new SqlDataAdapter(sql,sqlcon);
            adapter.Fill( ds,"xiala");
            comboBox1.DataSource=ds.Tables["xiala"];
            comboBox1.DisplayMember = "userName";
            comboBox1.ValueMember = "id";
            label14.Text = Convert.ToString(comboBox1.Text);
            label15.Text = jine;
            label16.Text = "0";
            label8.Text = jine;
            label10.Text = jine;
            label13.Text = "0";
            string str = comboBox1.SelectedValue.ToString();
            MessageBox.Show(str);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str = Convert.ToString( comboBox1.SelectedIndex);
            string str2 = Convert.ToString(textBox1.Text);
            string sql = "select count(*) FROM      [User] where id='" + str + "' and pwd='"+str2+"'";
            SqlConnection sqlcon = new SqlConnection(conStr);
            sqlcon.Open();
            try
            {
                SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
                if (Convert.ToInt32(sqlcom.ExecuteScalar()) > 0)
                {
                    MessageBox.Show("切换成功！");
                    label14.Text = Convert.ToString(comboBox1.Text);
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                sqlcon.Close();
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked==true)
            {
                label17.Visible = false;
                label11.Text = "签单扣减金额：";
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked==true)
            {
                label17.Visible = true;
                label11.Text = "签单打折比例：";
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {

            if (radioButton3.Checked == true)
            {
                label17.Visible = false;
                label11.Text = "最终收取金额：";
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                if (!(label13.Text.Equals( string.Empty)))
                {

                    if (textBox3.Text.Equals(string.Empty))
                    {
                        textBox3.Text = "0";
                    }
                        label13.Text = Convert.ToString(Convert.ToDouble(textBox3.Text));
                        label10.Text = Convert.ToString(Convert.ToDouble(label8.Text) - Convert.ToDouble(textBox3.Text));

                }


            }
            else if (radioButton2.Checked==true)
            {
                
                if (!(label13.Text.Equals( string.Empty)))
                {
                    if (textBox3.Text.Equals(string.Empty))
                    {
                        textBox3.Text = "0";
                    }
                    string str = textBox3.Text.Trim();
                    for (int i = 0; i < str.Length; i++)
                    {
                        if ((!Char.IsNumber(str[i])) && i == str.Length - 1)
                        {
                            if (str[i].Equals('.'))
                            {
                                break;
                            }
                            MessageBox.Show("请输入数字！");
                        }
                        else if (i==str.Length-1)
                        {
                            label13.Text = Convert.ToString(Convert.ToDouble(label8.Text)-Convert.ToDouble(label8.Text)*Convert.ToDouble(str));
                            label10.Text = Convert.ToString(Convert.ToDouble(label8.Text)*Convert.ToDouble(str));
                        }
                    }

                }
            }
            else if (radioButton3.Checked==true)
            {
                if (!(label13.Text.Equals( string.Empty)))
                {
                    if (textBox3.Text.Equals(string.Empty))
                    {
                        textBox3.Text = "0";
                    }
                    string str = textBox3.Text.Trim();
                    for (int i = 0; i < str.Length; i++)
                    {
                        if ((!Char.IsNumber(str[i])) && i == str.Length - 1)
                        {
                            if (str[i].Equals('.'))
                            {
                                break;
                            }
                            MessageBox.Show("请输入数字！");
                        }
                        else if (i==str.Length-1)
                        {
                            label13.Text = Convert.ToString(Convert.ToDouble(label8.Text)-Convert.ToDouble(str));
                            label10.Text = Convert.ToString(Convert.ToDouble(str));
                        }
                    }

                }
            }
        }

      public string youjine;
        private void button2_Click(object sender, EventArgs e)
        {
            bingkejiezhang frm = new bingkejiezhang();
            shuoming = label14.Text.Trim() + "优惠"+label13.Text.Trim()+"元";
            jine = Convert.ToString(label10.Text);
            youjine = label13.Text.Trim();
            
            frm.Activate();
            this.Close();
            
        }
        
    }
}
